package com.nur.noteishon;

import java.util.Calendar;

import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.format.DateFormat;
import android.widget.EditText;
import android.widget.TimePicker;

import com.nur.dto.Nota;

public class TimePickerFragment extends DialogFragment implements
		TimePickerDialog.OnTimeSetListener {
	private Nota nota;
	private boolean ini;
	private EditText txtHora;

	public TimePickerFragment(Nota nota, boolean _ini, EditText _txtHora) {
		ini = _ini;
		this.nota = nota;
		txtHora = _txtHora;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		// Use the current time as the default values for the picker
		final Calendar c = Calendar.getInstance();
		int hour = c.get(Calendar.HOUR_OF_DAY);
		int minute = c.get(Calendar.MINUTE);

		// Create a new instance of TimePickerDialog and return it
		return new TimePickerDialog(getActivity(), this, hour, minute,
				DateFormat.is24HourFormat(getActivity()));

	}

	public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
		Hora hora = new Hora(hourOfDay, minute);
		if (ini) {
			nota.setHoraInicio(hora.toString());
		} else {
			nota.setHoraFin(hora.toString());
		}
		txtHora.setText(hora.toString());
	}
}